﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.Shell;
using AxlfVSX.Core;
using EnvDTE;
using System.Windows.Forms;
using Aoxuelf.MDSTool.UI;

namespace Aoxuelf.MDSTool.Commands
{
    [CommandID(GuidList.guidMDSToolCmdSetString, PkgCmdIDList.cmdidInsertDALUpdate)]
    public class InsertDALUpdateCommand : DynamicCommand
    {
        public InsertDALUpdateCommand(Package package)
            : base(package)
        {
        }

        protected override bool CanExecute(OleMenuCommand command)
        {
            try
            {
                return FileCodeModelHelper.IsDataAccessClass(Dte);
            }
            catch
            {
                return false;
            }
        }

        protected override void OnExecute(OleMenuCommand command)
        {
            string sql = string.Empty;
            if (Clipboard.ContainsText())
            {
                sql = Clipboard.GetText();
            }

            InsertDALUpdateForm form = new InsertDALUpdateForm();
            form.ViewModel = new ViewModel.InsertDALUpdateViewModel { MethodName = "UpdateXX", Summary = "更新", SQL = sql, IsTransaction = true };
            form.ShowDialog();
        }
    }
}
